import React, { Component } from "react";
import service from "../../service";

class Login extends Component {
  state = {
    user: "123",
    pass: "456",
  };
  onSubmit = async () => {
    console.log(this.state.user)
    console.log(this.state.pass)
    console.log(service.Login);
    const res =
      (await service.Login(this.state.user, this.state.pass)) || {};
      console.log(res);
      
    if (res.codo === 0) {
      console.log("登录成功");
      alert("恭喜您，登录成功！");
      // this.$router.replace("/home")
    } else {
      console.log("登录失败，请重新登录");
      alert("登录失败，请重新登录");
    }
    // console.log(info);
    // const token = info.token;
    // const _id = info._id;
    // localStorage.setItem("token", token);
    // localStorage.setItem("id", _id);
  };
  render() {
    const { user, pass } = this.state;
    console.log(user);
    return (
      <div className="Login">
        <form className="form">
          <div className="formItem">
            <label htmlFor="username">用户名：</label>
            <input
              type="text"
              id="username"
              value={user}
              onChange={(e) => {
                this.setState({ user: e.target.value });
              }}
            />
          </div>
          <div className="formItem">
            <label htmlFor="password">密码：</label>
            <input
              type="password"
              id="password"
              value={pass}
              onChange={(e) => {
                this.setState({ pass: e.target.value });
              }}
            />
          </div>
          <div className="loginBtn">
            <button
              className="logindl"
              // onClick={this.onSubmit.bind(this)}
              onClick={this.onSubmit}
              type="button"
            >
              登录
            </button>
          </div>
        </form>
      </div>
    );
  }
}

export default Login;
